Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Jan 26, 2026

Based on PHPUnit 12, I've noticed some classes are mocked, but only passed allong as objects.
It doesn't bring any value, esp. for simple objects like Request and RequestStack

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

final class SomeTest extends TestCase
{
    public function test()
    {
-        $this->someMethod($this->createMock(Request::class));
+        $this->someMethod(new Request());
    }

    private function someMethod($someClass)
    {
    }
}

@TomasVotruba TomasVotruba force-pushed the tv-direct-object-over-mock branch from 269c761 to c437551 Compare January 26, 2026 11:53
@TomasVotruba TomasVotruba force-pushed the tv-direct-object-over-mock branch from c437551 to 680912f Compare January 26, 2026 12:02
@TomasVotruba TomasVotruba merged commit 6bc82f2 into main Jan 26, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the tv-direct-object-over-mock branch January 26, 2026 12:07
return $this->refactorArrayItem($node);
}

foreach ($node->getArgs() as $arg) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->isFirstClassCallable() should be checked early before ->getArgs()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants